package cn.stylefeng.guns.sys.modular.notice.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.notice.entity.DbNotice;
import cn.stylefeng.guns.sys.modular.notice.model.params.DbNoticeParam;
import cn.stylefeng.guns.sys.modular.notice.model.result.DbNoticeResult;
import cn.stylefeng.guns.sys.modular.notice.service.DbNoticeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 通知中心控制器
 *
 * @author author
 * @Date 2020-08-19 15:31:53
 */
@Controller
@RequestMapping("/dbNotice")
public class DbNoticeController extends BaseController {

    private String PREFIX = "/modular/notice/dbNotice";

    @Autowired
    private DbNoticeService dbNoticeService;

    /**
     * 跳转到主页面
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/dbNotice.html";
    }

    /**
     * 新增页面
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/dbNotice_add.html";
    }

    /**
     * 编辑页面
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/dbNotice_edit.html";
    }

    /**
     * 新增接口
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(DbNoticeParam dbNoticeParam) {
        this.dbNoticeService.add(dbNoticeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(DbNoticeParam dbNoticeParam) {
        this.dbNoticeService.update(dbNoticeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(DbNoticeParam dbNoticeParam) {
        this.dbNoticeService.delete(dbNoticeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(DbNoticeParam dbNoticeParam) {
        DbNotice detail = this.dbNoticeService.getById(dbNoticeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-08-19
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(DbNoticeParam dbNoticeParam) {
        return this.dbNoticeService.findPageBySpec(dbNoticeParam);
    }


    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-08-19
     */
    @RequestMapping("/complete")
    @ResponseBody
    public ResponseData complete(DbNoticeParam dbNoticeParam) {
        DbNoticeResult dbNoticeResult = this.dbNoticeService.findByParam(dbNoticeParam);
        dbNoticeParam.setId(dbNoticeResult.getId());
        dbNoticeParam.setContent(dbNoticeResult.getContent());
        dbNoticeParam.setDepartment(dbNoticeResult.getDepartment());
        dbNoticeParam.setSystem(dbNoticeResult.getSystem());
        dbNoticeParam.setState("0");
        dbNoticeParam.setAdminState("0");
        dbNoticeParam.setXxContent(dbNoticeResult.getXxContent());
        dbNoticeParam.setUserId(dbNoticeResult.getUserId());
        dbNoticeParam.setSpState("4");
        dbNoticeParam.setServiceType(dbNoticeResult.getServiceType());
        dbNoticeParam.setRemark(dbNoticeResult.getRemark());
        dbNoticeParam.setServiceId(dbNoticeResult.getServiceId());
        dbNoticeParam.setInterfaceApprovalId(dbNoticeResult.getInterfaceApprovalId());
        dbNoticeParam.setRevision(dbNoticeResult.getRevision());
        dbNoticeParam.setCreatedBy(dbNoticeResult.getCreatedBy());
        dbNoticeParam.setCreatedTime(dbNoticeResult.getCreatedTime());
        dbNoticeParam.setUpdatedBy(dbNoticeResult.getUpdatedBy());
        dbNoticeParam.setUpdatedTime(dbNoticeResult.getUpdatedTime());
        this.dbNoticeService.update(dbNoticeParam);
        return ResponseData.success();
    }

}


